#include<stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <savePic.h>
#include <time.h>

void save_jpg_picture(unsigned char *jpgData,int nByte,int count)
{
	char fileName[20] = "";
	
	time_t timer = time(NULL);
	char newtime[20] = {'\0'};
	char newdate[20] = {'\0'};
	strftime(newdate, 20, "%H:%M:%S", localtime(&timer));
	strftime(newtime, 20, "%Y-%m-%d", localtime(&timer));
	
	//printf("count = %d\n",count);
	sprintf(fileName,"./data/%s_%s_%d.jpg", newtime, newdate, count);
	int fd = open(fileName,O_RDWR | O_CREAT,0x664);
	if(fd < 0)
	{
        perror("open error:");
		return ;
	}
	int all = 0;
    int ret = 0;
	while( all < nByte)
	{		
		ret = write(fd,jpgData,nByte);
		all += nByte;
	}
	close(fd);
    count ++;
	return ;
}
